﻿using MyMeeting.Extensions;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyMeeting.ViewModels.Dialogs
{
    public class LoginViewModel : BindableBase, IDialogAware
    {
        public string Title =>"登录";

        public event Action<IDialogResult> RequestClose;

        public DelegateCommand LoginCommand { get; set; }

        private uint uid;
        private string userName;
        public uint Uid { get=>uid; set { uid = value;RaisePropertyChanged(); }}

        public string UserName { get => userName; set { userName = value;RaisePropertyChanged(); } }


        public LoginViewModel()
        {
          
            LoginCommand = new DelegateCommand(DoLogin);
        }

        private void DoLogin()
        {
            var user = new Dtos.MeetUser();
            user.Id = Uid;
            user.UserName = UserName;
            PrismManager.CurrentUser = user;
            RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
        }

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
        }
    }
}
